/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-17 11:14:29
 * @LastEditors: 北极星 8518826+liu-chaofans@user.noreply.gitee.com
 * @LastEditTime: 2023-12-16 16:46:43
 * @FilePath: /chatServer/include/msg.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef MSG_H
#define MSG_H
#define MSG_LENGTH 1024
#define USERNAME_LENGTH 128
#define PASSWORD_LENGTH 128
#define REASON_LENGTH 256
#define DEFAULT_LENGTH 128
enum
{
    CMD_LOGIN,
    CMD_LOGON,
    CMD_LOGOUT,
    CMD_ANSWER,
    CMD_LOGIN_ANSWER,
    CMD_LOGON_ANSWER,
    CMD_REG_USERINFO_ANSWER,
    CMD_REG_USERINFO,
    CMD_TRANS_FILE,
    CMD_GET_USERINFO,
    CMD_REQUEST_USERINFO,
    CMD_REQUEST_FRIENDSLIST,
    CMD_ANSWER_FRIENDLIST,
    CMD_CHAT_TO_FRIEND,
    CMD_GET_MSG,
    CMD_GET_MSG_ADDFRIEND,
    CMD_ADD_FRIEND_TO_LIST
};
enum
{
    MSG_TEXT
};
struct DataHeader
{
    unsigned short cmd;
    unsigned short datalength;
};

struct MSG_ADD : public DataHeader
{
    MSG_ADD()
    {
        this->cmd = CMD_ADD_FRIEND_TO_LIST;
        this->datalength = USERNAME_LENGTH;
    }
    char username1[USERNAME_LENGTH] = {0};
    char username2[USERNAME_LENGTH] = {0};
    char buf[MSG_LENGTH - sizeof(DataHeader) - USERNAME_LENGTH - USERNAME_LENGTH] = {0};
};

struct Login : public DataHeader
{
    Login()
    {
        this->cmd = CMD_LOGIN;
        this->datalength = USERNAME_LENGTH;
    }
    char username[USERNAME_LENGTH] = {0};
    char password[PASSWORD_LENGTH] = {0};
    char buf[MSG_LENGTH - sizeof(DataHeader) - USERNAME_LENGTH - PASSWORD_LENGTH] = {0};
};

struct Answer : public DataHeader
{
    Answer()
    {
                this->cmd = CMD_ANSWER;
        this->datalength = MSG_LENGTH;
    }
    unsigned int answer = true;
    char reason[REASON_LENGTH] = {0};
    char buf[MSG_LENGTH - sizeof(DataHeader) - REASON_LENGTH - 4] = {0};
};

struct Logon : public DataHeader
{

    Logon()
    {
        this->cmd = CMD_LOGON;
        this->datalength = MSG_LENGTH;
    }

    char username[USERNAME_LENGTH] = {0};
    char password[PASSWORD_LENGTH] = {0};
    char buf[MSG_LENGTH - sizeof(DataHeader) - USERNAME_LENGTH - PASSWORD_LENGTH] = {0};
};

struct UserInfo : public DataHeader
{
    UserInfo()
    {
        this->cmd = CMD_REG_USERINFO;
        this->datalength = MSG_LENGTH;
    }
    char path[DEFAULT_LENGTH] = {0};
    char username[DEFAULT_LENGTH] = {0};
    char nickname[DEFAULT_LENGTH] = {0};
    char signature[DEFAULT_LENGTH] = {0};
    int req = 0;
    char buf[MSG_LENGTH - DEFAULT_LENGTH - DEFAULT_LENGTH - DEFAULT_LENGTH - DEFAULT_LENGTH - 4 - sizeof(DataHeader)] = {0};
};

struct FileMsg : public DataHeader
{
    FileMsg()
    {
        this->cmd = CMD_TRANS_FILE;
        this->datalength = MSG_LENGTH;
    }
    char username[USERNAME_LENGTH] = {0};
    char buf[MSG_LENGTH - USERNAME_LENGTH - sizeof(DataHeader)] = {0};
};

struct Request : public DataHeader
{
    Request()
    {
        this->cmd = CMD_REQUEST_USERINFO;
        this->datalength = MSG_LENGTH;
    }
    char username[USERNAME_LENGTH] = {0};
    char buf[MSG_LENGTH - USERNAME_LENGTH - sizeof(DataHeader)] = {0};
};

struct ChatPackage : public DataHeader
{
    ChatPackage()
    {
        this->cmd = CMD_CHAT_TO_FRIEND;
        this->datalength = MSG_LENGTH;
    }
    unsigned int msg_type = MSG_TEXT;
    char from[USERNAME_LENGTH] = {0};
    char to[USERNAME_LENGTH] = {0};
    char msgbody[MSG_LENGTH - sizeof(DataHeader) - USERNAME_LENGTH - USERNAME_LENGTH] = {0};
};

struct OnLineUserList
{
    char username[USERNAME_LENGTH]={0};
    int socket;
};

struct GetMsg:public DataHeader
{
    GetMsg()
    {
        this->cmd = CMD_GET_MSG;
        this->datalength = MSG_LENGTH;
    }
    char username[USERNAME_LENGTH]={0};
    char buf[MSG_LENGTH - USERNAME_LENGTH - sizeof(DataHeader)]={0};
};
struct AnswerMsg:public DataHeader
{
    AnswerMsg()
    {
        this->cmd = CMD_GET_MSG;
        this->datalength = MSG_LENGTH;
    }
    char username[USERNAME_LENGTH]={0};
    char pic[USERNAME_LENGTH]={0};
    char msgbody[MSG_LENGTH-sizeof(DataHeader)-USERNAME_LENGTH-USERNAME_LENGTH]={0};
};
#endif
